﻿<%@ Page Language="C#" MasterPageFile="~/admin/Admin.Master" AutoEventWireup="true"
    Codebehind="fileManagers.aspx.cs" Inherits="CMS.admin.fileManagers" Title="Hệ thống quản trị nội dung - quản lý file hệ thống" %>

<%@ Register Assembly="ComponentArt.Web.UI" Namespace="ComponentArt.Web.UI" TagPrefix="ComponentArt" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <input type="hidden" name="<%=ActionTag%>" />
    <div style="border: solid 1px #ccc;">
        <div id="toolbox">
            <div class="header" style="float: left; margin-left: -40px;">
                <img src="../images/Toolbox/icon-48-extension.png" alt="" id="imgHeader" />
                Quản lý file hệ thống
            </div>
        </div>
    </div>
    <div style="height: 10px;">
        &nbsp;</div>
        
    <div id="content-box" >
        <div class="t">
            <div class="t">
                <div class="t">
                </div>
            </div>
        </div>
        <div class="m" style="height: 100%;">
            <table class="Header" width="850px" border="0" cellpadding="5">
                <tr>
                    <td width="310px">
                        <img src="../images/file/folder.gif" align="middle" />&nbsp;
                        <input type="text" name="txtPath" id="txtPath" value="<%= WebPath()%>" size="35" />
                        <input type="submit" onclick="javascript:goUrl(); return false;" value="Go" />
                    </td>
                    <td width="200px">
                        <img src="../images/icon/folderup.gif" align="middle">&nbsp;<a id="up" runat="server">Chuyển
                            lên thư mục trên (Up)</a>
                    </td>
                    <td>
                        &nbsp</td>
                </tr>
            </table>
        </div>
    </div>
    <div style="width: 100%;height:520px;">
        <asp:GridView ID="GridView1" AllowSorting="true" AllowPaging="true" runat="server" CssClass="Grid" FooterStyle-CssClass="GridFooter"
        PagerStyle-CssClass="Numbered"  RowStyle-CssClass="Row" HeaderStyle-CssClass="HeadingCell" HeaderStyle-BorderStyle="solid" 
        HeaderStyle-BorderWidth="1px" HeaderStyle-BorderColor="#BFDBF5" 
         HeaderStyle-Height="30px"
            Width="100%" PageSize="15" AutoGenerateColumns="False" OnPageIndexChanging="GridView1_PageIndexChanging">
            <Columns>
                <asp:TemplateField HeaderText="#" HeaderStyle-BorderColor="#BFDBF5" ItemStyle-Width="40" ItemStyle-HorizontalAlign="Center">
                    <ItemTemplate>
                        <asp:CheckBox ID="checked_" runat="server" />
                        <asp:HiddenField ID="fileName" Value='<%#Eval("Name")%>' runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:ImageField   DataImageUrlField="fileIconLookup" ItemStyle-HorizontalAlign="Center" HeaderText="Pictures">
                    <ItemStyle Height="16px" Width="16px" HorizontalAlign="center"/>
                    <ControlStyle Height="16px" Width="16px"/>
                    <FooterStyle Height="16px" Width="16px" />
                    <HeaderStyle Height="16px" Width="16px" />
                </asp:ImageField>
                <asp:TemplateField HeaderText="T&#234;n file" ItemStyle-HorizontalAlign="left">
                    <ItemTemplate>
                        <%#Eval("strFileLink")%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField HeaderText="Dung lượng (KB)" DataField="Size" />
                <asp:BoundField HeaderText="Thuộc t&#237;nh" DataField="Attr" />
            </Columns>
            <HeaderStyle BackColor="#BFDBF5" BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px" CssClass="HeadingCell" Height="30px" />
            <FooterStyle CssClass="GridFooter" />
            <RowStyle CssClass="Row" BorderColor="#BFDBF5" />
            <PagerStyle CssClass="Numbered" />
        </asp:GridView>
        
        
        <%--rent body table rows--%>
        <input type="hidden" id="newName" name="newName" runat="server" />
    <div style="border: solid 1px #ccc;" style="height:160px;vertical-align:top;">
        <div id="Div1">
            <table>
                <tr>
                    <td width="25px">
                        <img src="../images/file/folder.gif" align="middle" />&nbsp
                    </td>
                    <td width="260px">
                        <asp:TextBox ID="folderName" name="folderName" runat="server"></asp:TextBox>
                    </td>
                    <td width="180px">
                        <a href="javascript:newfolder();">
                            <img src="../images/icon/newfolder.gif" width="19px" height="16px" align="middle" />
                            &nbsp;Tạo thư mục</a>
                    </td>
                    <td width="140px">
                        <a href="javascript:confirmfiles('copy');">
                            <img src="../images/icon/copy.gif" align="middle" />&nbsp;Copy đến thư mục</a>
                    </td>
                    <td width="140px">
                        <a href="javascript:confirmfiles('move');">
                            <img src="../images/icon/move.gif" align="middle" />&nbsp;Chuyển đến thư mục</a>
                    </td>
                    <td width="100px">
                        &nbsp</td>
                </tr>
                <tr>
                    <td>
                        <img src="../images/file/generic.gif" align="middle" />
                        &nbsp;
                        </td>
                        <td>
                        <asp:FileUpload ID="fileUpload" runat="server" />
                    </td>
                    <td ></td>
                    <td>
                        <a href="javascript:upload();">
                            <img src="../images/icon/upload.gif" width="18px" height="16px" align="middle" />&nbsp;Tải
                            file</a>
                    </td>
                    <td>
                        <a href="javascript:confirmfiles('delete');">
                            <img src="../images/icon/delete.gif" width="18px" height="16px" align="middle" />&nbsp;Xóa</a>
                    </td>
                    <td>
                        <a href="javascript:confirmfiles('rename');">
                            <img src="../images/icon/rename.gif" align="middle" />&nbsp;Đổi tên</a>
                    </td>
                    <td>
                        <a href="javascript:confirmfiles('zip');">
                            <img src="../images/icon/zip.gif" align="middle" />
                            &nbsp;Nén file</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>        
    </div>


    <script language="javascript" type="text/javascript">	
		// create new folder
		function newfolder() {		
		var cNewFolder=document.getElementById("<%=folderName.ClientID %>");
			if (cNewFolder.value == '') {
				alert('Chưa nhập tên thư mục, vui lòng nhập tên thư mục vào ô bên cạnh.');
				cNewFolder.focus();
				return;
			}
			document.forms[0].action.value = 'newfolder';
			document.forms[0].submit();
		}
		
		function upload() {
		var cFUpload=document.getElementById("<%=fileUpload.ClientID %>");
            if (cFUpload.value == '') {
				alert('Vui lòng chọn 1 file để tải.');
				cFUpload.focus();
				return;
			}
			document.forms[0].action.value = 'upload';
			document.forms[0].submit();
		}
		
		function goUrl(){		
		var strHref=window.location.href;
		var strOldPath;
		var strNewUrl;
		var strQueryString='';
		
		/*  admin/filemanagers.aspx
            admin/filemanagers.aspx?path=/Uploads/tttttttt&sort=Name
        */
        var url=strHref;
  //      alert(strHref);
		if(strHref.indexOf("?")>-1){
//		alert(strHref.indexOf("?"));
		     strQueryString=strHref.substr(strHref.indexOf("?")).toLowerCase();
		    url=strHref.substr(0,strHref.indexOf("?"));		    
		}
		
		var txtPath=document.getElementById('txtPath');
//		alert(txtPath);
//		alert(txtPath.value);
		    if(txtPath ==null || txtPath.value=='' || txtPath.value=='~/Uploads/'){
		    txtPath.value='/Uploads/';
		    }
		    if(txtPath.value !='/Uploads/'){
		    txtPath.value=Trim(txtPath.value);
		        strQueryString='?path='+txtPath.value+'&sort=name';
		        
		    }
//		alert('123'+strQueryString);
		strNewUrl=url+strQueryString;
//		alert('strNewUrl:    :'+strNewUrl);
		window.location=strNewUrl;		
		}
		
		// confirm file list and target folder
		
		function confirmfiles(sAction) {		
		var cNewFolder=document.getElementById("<%=folderName.ClientID %>");
			var nMarked = 0;
			var sTemp = '';
            for (var i = 0; i < document.forms[0].elements.length; i++) {
				if (document.forms[0].elements[i].checked && 
				 document.forms[0].elements[i].name.indexOf('checked_') > -1) { 
					if (sAction == 'rename') {
						var sFilename = '';
            			var sNewFilename = '';
						sNewFilename = prompt('Enter new name for ' + sFilename, sFilename);
						if (sNewFilename != null) {
						    document.getElementById("<%=newName.ClientID %>").value=sNewFilename;
						}
					}
					nMarked = nMarked + 1;
				}
			}
			if (nMarked == 0) {
				alert('Chưa chọn mục nào, vui lòng chọn một mục!.');
				return;
			}

			sTemp = 'Bạn chắc chắn muốn ' + sAction + ' the ' + nMarked + ' những mục đã chọn?'
			if (sAction == 'copy' || sAction == 'move') {
				sTemp = 'Are you sure you want to ' + sAction + ' the ' + nMarked + ' checked item(s) to the "' + cNewFolder.value + '" folder?'
				if (cNewFolder.value == '') {
				    cNewFolder.focus();
					alert('No destination folder provided. Enter a folder name.');
					return;
				}
			}
			var confirmed = false;
			if (sAction == 'copy' || sAction == 'rename') {
			
			    confirmed = true;
			} else {
			    confirmed = confirm(sTemp);
			}

			if (confirmed) { 
				document.forms[0].action.value = sAction;
				document.forms[0].submit();
			}

		}
		
		
    </script>

</asp:Content>
